<?
if(!defined ('U_MOD'))
{
	echo"<meta http-equiv='refresh' content='0;url=/index.php'>";
	exit;
}

$showForm=1;

if (!isset($FormError))
{
	$i=0;
	$FormError=array();
}

if (isset($act) && ($act==1 || $act==2))
{
	if ($act==1){$ActionUrl=1;  $ActionButton=_ADDNEW_;}
	if ($act==2){$ActionUrl=2;  $ActionButton=_EDITE_; $midActionUrl='&sid='.$sid;}

	if ($act==1 || $act==2)
	{
		$querySUrlCheck=mysql_query("SELECT * FROM ".$PortalPref.$amk." WHERE settings_id='".$sid."'");
		/*if (mysql_num_rows($queryModuleCheck)!=0 && $act==1)
		{
			$FormError[$i]=_MODULE_EXIST_;
			$i++;
		}else*/
		if(mysql_num_rows($querySUrlCheck)==0 && $act==2)
		{
			$FormError[$i]=_NO_SETTINGS_FOR_EDITE_;
			$i++;
			$showForm=0;
			echo"<meta http-equiv='refresh' content='2;url=/admin.php?amk=".$amk."'>";
		}else
		{
			if (!isset($surl) || $surl=='')
			{
				$FormError[$i]=_NO_SURL_;
				$i++;
			}

			if (empty($FormError))
			{
				if ($act==1)
				{

				}elseif($act==2)
				{
					$querySetUrl="UPDATE ".$PortalPref.$amk."
					SET
						settings_value='".$surl."'
					WHERE
						settings_id='".$sid."'
					";
				}

				if (mysql_query($querySetUrl))
				{
					$showForm=0;
					print '<p align="center">'._OPERATION_SUCCESS_.'</p>';
					echo"<meta http-equiv='refresh' content='0;url=/admin.php?amk=".$amk."'>";
				}else
				{
					$FormError[$i]=_BAD_SQL_;
					$i++;
				}
			}
		}
	}
}elseif(isset($act) && $act==3)
{
	$ActionUrl=2;  $ActionButton=_EDITE_;
	$queryGetUrl=mysql_query("SELECT * FROM ".$PortalPref.$amk." WHERE settings_id='".$sid."'");
	if (mysql_num_rows($queryGetUrl)!=1)
	{
		$FormError[$i]=_NO_SETTINGS_FOR_EDITE_;
		$i++;
		$showForm=0;
		echo"<meta http-equiv='refresh' content='2;url=/admin.php?amk=".$amk."'>";
	}else
	{
		while($resultGetUrl=mysql_fetch_assoc($queryGetUrl))
		{
			$surl=$resultGetUrl['settings_value'];
		}
		$midActionUrl='&sid='.$sid;
	}
}else
{
	$ActionUrl=1;  $ActionButton=_ADDNEW_;
}

print '<p>';
getErrorList($FormError);
print '</p>';

if ($showForm==1)
{
	print '<form method="post" name="ModuleFrm" action="'.$portal_url.'/admin.php?amk='.$amk.'&apk='.$apk.'&act='.$ActionUrl.''.$midActionUrl.'">
		<table width="80%" align="center">
			<tr>
				<td>'._SETTINGS_PORTAL_URL_.'</td>
				<td><input type="text" name="surl" value="'.$surl.'"></td>
			</tr>
			<tr>
				<td colspan="2"><input type="submit" value="'.$ActionButton.'"></td>
			</tr>
		</table>
	</form>';
}
?>